#version 430 core
layout(location = 0)in vec3 vertPos;
layout(location = 1)in vec3 vertColor;
layout(location = 2)in vec3 vertNormal;

out vec3 color;
out vec3 varyingNormal;

struct material_properties{
    vec4 ambient;
    vec4 diffuse;
    vec4 specular;
    float shiness;
};
uniform material_properties material;

uniform mat4 mvMatrix;
uniform mat4 projMatrix;
uniform mat3 normalMatrix;
uniform bool hasMaterial;
uniform bool partColor;
uniform vec3 pureColor;
uniform vec3 lightDir;

void main()
{
    varyingNormal = normalize(normalMatrix*vertNormal);
    float diff = max(0.0,dot(varyingNormal,normalize(lightDir)));

    if(hasMaterial){
        color = (material.ambient+material.diffuse+material.specular).xyz;
    }else{
        if(partColor){
            color = vertColor;
        }else{
            color = pureColor;
        }
    }

    color*=diff;

    gl_Position = mvMatrix*vec4(vertPos,1.0f);

}
